home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Tricks of the Mac Game Programming Gurus
/
TricksOfTheMacGameProgrammingGurus.iso
/
More Source
/
Libraries
/
SpriteEngine
/
SE Hunter & Evader 2
/
SpriteHanders.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-03-11
|
3KB
|
122 lines
#include "SpriteTools.h"
// SpriteTools.h includes SpriteHandlers.h
/*** Custom handlers - application dependent ***
Edit this as necessary. It should always include the following three routines:
MoveSprite: move the sprite
HitSprite: handle collisions between two sprites
InitSprites: Load all faces and create initial sprites
***/
GrafPtr firstFace, secondFace, thirdFace;
static Point gPlayerPosition;
void MoveSprite(SpritePtr theSprite)
{
Point vector;
switch (theSprite->kind)
{
case playerSprite:
GetMouse(&theSprite->position);
gPlayerPosition = theSprite->position;
KeepOnScreen(theSprite);
break;
case hunterSprite:
theSprite->fixedPointPosition.h += theSprite->speed.h;
theSprite->fixedPointPosition.v += theSprite->speed.v;
theSprite->position.h = theSprite->fixedPointPosition.h >> 4;
theSprite->position.v = theSprite->fixedPointPosition.v >> 4;
KeepOnScreenFixed(theSprite);
vector.h = gPlayerPosition.h - theSprite->position.h;
vector.v = gPlayerPosition.v - theSprite->position.v;
theSprite->speed.h = vector.h / 8;
theSprite->speed.v = vector.v / 8;
break;
case evaderSprite:
theSprite->fixedPointPosition.h += theSprite->speed.h;
theSprite->fixedPointPosition.v += theSprite->speed.v;
theSprite->position.h = theSprite->fixedPointPosition.h >> 4;
theSprite->position.v = theSprite->fixedPointPosition.v >> 4;
KeepOnScreenFixed(theSprite);
vector.h = gPlayerPosition.h - theSprite->position.h;
vector.v = gPlayerPosition.v - theSprite->position.v;
theSprite->speed.h = -vector.h / 8;
theSprite->speed.v = -vector.v / 8;
/* Keep this sprite a bit inside the bounds so it doesn't just stand in a corner. */
if (theSprite->position.h < 50)
{
theSprite->position.h = 50;
theSprite->fixedPointPosition.h = theSprite->position.h << 4;
}
if (theSprite->position.h > gOffScreen->portRect.right - theSprite->face->portRect.right - 50)
{
theSprite->position.h = gOffScreen->portRect.right - theSprite->face->portRect.right - 50;
theSprite->fixedPointPosition.h = theSprite->position.h << 4;
}
if (theSprite->position.v < 50)
{
theSprite->position.v = 50;
theSprite->fixedPointPosition.v = theSprite->position.v << 4;
}
if (theSprite->position.v > gOffScreen->portRect.bottom - theSprite->face->portRect.bottom - 50)
{
theSprite->position.v = gOffScreen->portRect.bottom - theSprite->face->portRect.bottom - 50;
theSprite->fixedPointPosition.v = theSprite->position.v << 4;
}
break;
}
} /*MoveSprite*/
void HitSprite(SpritePtr theSprite, SpritePtr anotherSprite)
{
} /*HitSprite*/
void InitSprites()
{
SpritePtr theSprite;
/*Load all pictures*/
firstFace = LoadFaceFromCicn(128); /*cicn resource #128.*/
secondFace = LoadFaceFromCicn(129); /*cicn resource #129.*/
thirdFace = LoadFaceFromCicn(130); /*cicn resource #130.*/
/*Create sprites*/
theSprite = NewSprite();
theSprite->kind = hunterSprite;
theSprite->face = firstFace;
SetPt(&theSprite->position, 100, 100);
theSprite = NewSprite();
theSprite->kind = playerSprite;
theSprite->face = secondFace;
SetPt(&theSprite->position, 50, 50);
theSprite = NewSprite();
theSprite->kind = evaderSprite;
theSprite->face = thirdFace;
SetPt(&theSprite->position, 150, 150);
} /*InitSprites*/